
package com.huaweicloud.haydn.delivercore.agent.service.metadata;

import com.huaweicloud.haydn.delivercore.agent.common.exception.BusinessException;
import com.huaweicloud.haydn.delivercore.agent.dto.excel.DbExcelDto;
import com.huaweicloud.haydn.delivercore.agent.dto.excel.FieldEmptyExcelDto;
import com.huaweicloud.haydn.delivercore.agent.dto.excel.FieldExcelDto;
import com.huaweicloud.haydn.delivercore.agent.dto.excel.TableExcelDto;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

/**
 * @since 2022-09-26
 */
public interface DatabaseUtil {

    String getURL(String hostname, String port, String databaseName);

    String getURLException(String hostname, String port, String databaseName);

    String getDriverClass();

    String getAllDatabasesSql() throws BusinessException;

    String getSelectedDatabasesSql(String dbNames) throws BusinessException;

    String getAllSchemasSql();

    String getAllTablesSql();

    String getAllTablesByDbSql(String dbNames);

    String getSelectedTableSql(String dbNames, String tableNames);

    String getAllFieldsSql();

    String getAllFieldsByDbSql(String dbNames);

    String getAllFieldsSql(String dbNames, String tableNames);

    List<String> getAllSchemas(int firstSize, int maxSize) throws BusinessException;

    List<String> getAllDatabases(int firstSize, int maxSize) throws BusinessException;

    long getSchemaNum() throws BusinessException;

    long getDatabasesNum() throws BusinessException;

    List<String> getAllTables(int firstSize, int maxSize, String schema) throws BusinessException;

    long getTableNum(String schema) throws BusinessException;

    Connection getConnection() throws BusinessException;

    void init(String dbHostname, String dbPort, String dbDatabaseName, String dbUsername, String dbPassword,
        String dbType, String dbNameStr, String tableNamesStr);

    long executeCountSql(String countSql);

    List<DbExcelDto> getAllDbs(String datalinkName, String dbNames, String schemas);

    List<TableExcelDto> getAllTables(String datalinkName, String dbNames, String schemas, String tableNames);

    List<FieldExcelDto> getAllFields(String datalinkName, String dbNames, String schemas, String tableNames);

    List<FieldEmptyExcelDto> getAllEmptyRateFields(String datalinkName, String dbNames, String schemas,
        Map<String, List<String>> fieldTableMap);
}
